﻿@inherits BaseComponent

<div class="ws-chart">
    <div class="ant-card ant-card-bordered" style="height:100%;">
        <div class="ant-card-head">
            <div class="ant-card-head-wrapper">
                <div class="ant-card-head-title">@option?.Title</div>
            </div>
        </div>
        <div class="ant-card-body">
            <KChart @ref="chart" Id="chart" />
        </div>
    </div>
</div>

@code {
    private KChart chart;
    private ChartCardOption option;

    public void SetOption(ChartCardOption option)
    {
        this.option = option;
    }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await base.OnAfterRenderAsync(firstRender);
        if (firstRender)
        {
            var info = option?.Charts?.FirstOrDefault();
            if (info?.Type == "Line")
                await chart?.ShowLineAsync(info?.Title, info?.Datas);
            else if (info?.Type == "Bar")
                await chart?.ShowBarAsync(info?.Title, info?.Datas);
            else if (info?.Type == "Pie")
                await chart?.ShowPieAsync(info?.Title, info?.Datas);
        }
    }
}